import { Type } from "class-transformer";
import { IsString, IsOptional, MinLength, MaxLength, Matches, IsNotEmpty, IsInt } from "class-validator";

/**
 * 菜单更新参数DTO
 */
export class UpdateMenuDto {
  @IsOptional()
  @IsString({ message: "菜单名称必须是字符串" })
  @MinLength(2, { message: "菜单名称长度不能少于2个字符" })
  @MaxLength(50, { message: "菜单名称长度不能超过50个字符" })
  name?: string;

  @IsOptional()
  @IsString({ message: "菜单路径必须是字符串" })
  @Matches(/^\/[a-zA-Z0-9\-_\/]*$/, { message: "菜单路径格式不正确，必须以/开头，只能包含字母、数字、-、_和/" })
  @MaxLength(200, { message: "菜单路径长度不能超过200个字符" })
  path?: string;

  @Type(() => Number) // 将入参转换为 number
  @IsNotEmpty({ message: "排序值不能为空" })
  @IsInt({ message: "排序值必须是整数" })
  order: number;

  @IsOptional()
  @IsString({ message: "访问控制必须是字符串" })
  @MaxLength(100, { message: "访问控制长度不能超过100个字符" })
  acl?: string;
}
